package com.examp.shardingSphere.controller;

import com.examp.shardingSphere.entity.User;
import com.examp.shardingSphere.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @description: UserController
 * @Date : 2021/3/10
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/save")
    public String insert() {
        User user = new User();
        user.setNickname("zhangsan" + new Random().nextInt());
        user.setPassword("1234567");
        user.setSex(1);
        Calendar calendar = Calendar.getInstance();
        calendar.set(2024, Calendar.DECEMBER-1, 1, 17, 10);
        user.setBirthday(calendar.getTime());
        userMapper.addUser(user);
        return "success";
    }

    @GetMapping("/list")
    public List<User> list() {
        return userMapper.findUsers();
    }
}